/**
 * 
 */
package com.jyh.util;

public class ExeceptionUtils {
	/**
	 * 打印具体异常信息
	 * 
	 * @param ex
	 * @return
	 */
	public static String getExceptionAllMsg(Exception ex) {
		String sOut = "\n";
		sOut += "===========server========exception============start===============\r\n";
		sOut += ex.toString() + "\r\n";
		StackTraceElement[] trace = ex.getStackTrace();
		for (StackTraceElement s : trace) {
			sOut += "\tat " + s + "\r\n";
		}
		sOut += "===========server=========exception===========end=================\r\n";
		return sOut;
	}

	/**
	 * 打印具体异常信息
	 * 
	 * @param ex
	 * @return
	 */
	public static String getExceptionAllMsg(Throwable ex) {
		String sOut = "\n";
		sOut += "===========server========exception============start===============\r\n";
		sOut += ex.toString() + "\r\n";
		StackTraceElement[] trace = ex.getStackTrace();
		for (StackTraceElement s : trace) {
			sOut += "\tat " + s + "\r\n";
		}
		sOut += "===========server=========exception===========end=================\r\n";
		return sOut;
	}

	/**
	 * 获取当前方法的调用者
	 * 
	 * @return
	 */
	public static String getCall(int parentLevel) {
		StackTraceElement stack[] = Thread.currentThread().getStackTrace();
		if(parentLevel >= stack.length){
			return "超出长度";
		}
		if(parentLevel == -1){
			return "\t" + stack[stack.length - 1];
		}
		return "\t" + stack[parentLevel];
	}
}
